def selection_sort(arr):
    n = len(arr)
    for i in range(n-1):
        # 第i次从[i,n-1]找最小值
        min_idx = i
        for j in range(i+1, n):
            if arr[j] < arr[min_idx]:
                min_idx = j
        # 交换最小值到正确位置
        arr[i], arr[min_idx] = arr[min_idx], arr[i]

a = [4, 3, 2, 1]
selection_sort(a)
print(' '.join(map(str, a)))
